package resources.resourceloader;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.Resource;

public class ResorceLoaderDemo {
    @Test
    public void Demo1(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext();
//        Resource实例
        Resource resource = context.getResource("2023.3.9.txt");
        System.out.println(resource.getFilename());
    }

    @Test
    public void Demo2() {
        ApplicationContext context =
                new FileSystemXmlApplicationContext();
        Resource resource = context.getResource("2023.3.9.txt");
        System.out.println(resource.getFilename());
    }

    //Spring将采用和ApplicationContext相同的策略来访问资源。
    // 也就是说，如果ApplicationContext是FileSystemXmlApplicationContext，res就是FileSystemResource实例；
    // 如果ApplicationContext是ClassPathXmlApplicationContext，res就是ClassPathResource实例

}
